package com.msu.nava.fragment;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListPopupWindow;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import com.msu.nava.R;
import com.msu.nava.activity.CIListActivity;
import com.msu.nava.activity.DiagnoseActivity;

public class HomeFragment extends Fragment {

  private Button btn_nk;//内科
  private Button btn_wk;//外科
  private Button btn_ek;//儿科
  private Button btn_wgk;//五官科
  private Button btn_fck;//妇产科
  private Button btn_ganmao;//感冒
  private Button btn_bumei;//不寐
  private Button btn_fuxie;//腹泻
  private Button btn_weitong;//胃痛

  @Override
  public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
  }

  @Nullable
  @Override
  public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.frg_home, container, false);
    setButtons(view);
    setBtnListener(view);
    return view;
    /*设置listview和scorllview不冲突*/
//    listView.setOnTouchListener(new View.OnTouchListener() {
//      @Override
//      public boolean onTouch(View v, MotionEvent event) {
//        v.getParent().requestDisallowInterceptTouchEvent(true);
//        return false;
//      }
//    });

  }
  private class CommonSickListener implements View.OnClickListener{
    private String iname;
    public CommonSickListener(String iname){
      this.iname = iname;
    }
    @Override
    public void onClick(View v) {
      Intent intent = new Intent(getContext(),DiagnoseActivity.class);
      intent.putExtra("iname",iname);
      startActivity(intent);
    }
  }
  private class CategoryListener implements View.OnClickListener{
    private String category;
    public CategoryListener(String category){
      this.category = category;
    }
    @Override
    public void onClick(View v) {
      Intent intent = new Intent(getContext(),CIListActivity.class);
      intent.putExtra("category",category);
      startActivity(intent);
    }
  }

  private void setButtons(View view) {
    btn_nk = (Button) view.findViewById(R.id.btn_nk);
    btn_wk = (Button) view.findViewById(R.id.btn_wk);
    btn_ek = (Button) view.findViewById(R.id.btn_ek);
    btn_wgk = (Button) view.findViewById(R.id.btn_wgk);
    btn_fck = (Button) view.findViewById(R.id.btn_fck);
    //常见
    btn_ganmao = (Button) view.findViewById(R.id.button);
    btn_bumei = (Button) view.findViewById(R.id.button3);
    btn_fuxie = (Button) view.findViewById(R.id.button4);
    btn_weitong = (Button) view.findViewById(R.id.button2);
  }


  private void setBtnListener(View view) {
    //科室
    btn_nk.setOnClickListener(new CategoryListener("中医内科"));
    btn_ek.setOnClickListener(new CategoryListener("中医儿科"));
    btn_fck.setOnClickListener(new CategoryListener("中医妇产科"));
    btn_wk.setOnClickListener(new CategoryListener("中医外科"));
    btn_wgk.setOnClickListener(new CategoryListener("中医五官科"));
    //常见
    btn_ganmao.setOnClickListener(new CommonSickListener("感冒"));
    btn_bumei.setOnClickListener(new CommonSickListener("不寐(失眠)"));
    btn_weitong.setOnClickListener(new CommonSickListener("胃痛"));
    btn_fuxie.setOnClickListener(new CommonSickListener("泄泻（腹泻）"));

  }

}
